import React, { lazy, Suspense } from 'react';
import {BrowserRouter as Router, Route, Redirect} from 'react-router-dom'
// 鉴权路由
import AuthRoute  from '@/components/AuthRoute/indx.js'
import CacheRoute, { CacheSwitch } from 'react-router-cache-route'
// import KeepAlive, { AliveScope } from 'react-activation'
import '@/App.css';

// 导入组件
// import Home from '@/views/Home/Home.jsx'
import Layout from '@/pages/Layout/Layout.jsx'
// 按需导入
const Favorate = lazy(()=>import('@/views/Favorate/Favorate.jsx'))
const Login = lazy(()=>import('@/pages/Login/Login.jsx'))
 
function App() {
  return (
    // <AliveScope>
    <Router>
      <Suspense fallback={<div>loading...</div>}>
      {/* <KeepAlive> */}
      <div className="App">
      <CacheSwitch>
          <CacheRoute className='CacheSwitch'   exact path='/' render={()=><Redirect to='chuko_blog'></Redirect>}></CacheRoute>
          <CacheRoute className='CacheSwitch'  path='/chuko_blog' component={Layout}></CacheRoute>
          <Route path='/Login' component={Login}></Route>
          <Route path='/User' component={Login}></Route>
            {/* 配置登录后，才能访问的页面 */} 
          <AuthRoute exact path="/favorate" component={Favorate} />
          </CacheSwitch>  
        </div>
      {/* </KeepAlive> */}
      </Suspense>
    </Router>
    // </AliveScope>
  );
}

export default App;
